package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

class zcda {
   Workbook a;
   zoz b;
   com.aspose.cells.a.f.zi c = null;
   zcdp d = null;
   private static final com.aspose.cells.b.c.a.za e = new com.aspose.cells.b.c.a.za(new String[]{"http://schemas.microsoft.com/office/2007/relationships/ui/extensibility", "http://schemas.microsoft.com/office/2006/relationships/ui/extensibility", "http://schemas.microsoft.com/office/2006/relationships/ui/userCustomization", "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "http://schemas.microsoft.com/office/2007/relationships/customDataProps", "http://schemas.microsoft.com/office/2006/relationships/attachedToolbars", "http://schemas.microsoft.com/office/2011/relationships/timelineCache", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/powerPivotData", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/connections", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"});

   static zbxz a(com.aspose.cells.a.f.zi var0, String var1) throws Exception {
      com.aspose.cells.a.f.zh var2 = var0.a(var1);
      if (var2 == null) {
         return null;
      } else {
         com.aspose.cells.b.a.d.zm var3 = var0.a(var2);
         byte[] var4 = new byte[(int)var2.a()];
         var3.a(var4, 0, var4.length);

         try {
            var3.a();
         } catch (Exception var6) {
            ;
         }

         return new zbxz(var4);
      }
   }

   zcda(Workbook var1) {
      this.a = var1;
      this.b = new zoz(var1);
      this.c = var1.b.b.b;
   }

   byte[] a(zbxz var1) {
      int var2 = var1.b();
      return var1.a(var2);
   }

   void a() throws Exception {
      this.b();
      String var1 = this.b.g;
      if (this.c.a(var1, true) == -1) {
         throw new CellsException(4, "Invalid Excel2007Xlsb file format");
      } else {
         zcfw var2 = null;

         try {
            this.c();
            zceh var3 = new zceh(this);
            var3.a(a(this.c, var1), this.c);
            this.d(this.c);
            this.b(this.c);
            String var4 = "docProps/core.xml";
            zaix var5 = new zaix(this.b);
            var2 = zasr.a(this.c, var4, true);
            var5.a(var2);
            var2.c();
            String var6 = "docProps/app.xml";
            if (this.c.a(var6, false) != -1) {
               zaiw var7 = new zaiw(this.b);
               var2 = zasr.a(this.c, var6, true);
               var7.a(var2);
               var2.c();
            }

            String var13 = "docProps/custom.xml";
            if (this.c.a(var13, false) != -1) {
               zaiy var8 = new zaiy(this.b);
               var2 = zasr.a(this.c, var13, true);
               var8.a(var2);
               var2.c();
            }

            String var14 = "xl/styles.bin";
            this.d = new zcdp(this);
            this.d.a(a(this.c, var14));
            String var9 = "xl/sharedStrings.bin";
            if (this.c.a(var9, false) != -1) {
               this.b(a(this.c, var9));
            }

            this.c(this.c);
            this.a(this.c);
            this.a.b.a();
            this.f();
            this.e();
            this.d();
            this.a(this.a.b.i.f);
         } finally {
            if (var2 != null) {
               var2.c();
            }

            this.a.b.b.a();
         }

      }
   }

   private void b() throws Exception {
      this.b.g = "xl/workbook.bin";
      String var1 = "_rels/.rels";
      if (this.c.a(var1, true) != -1) {
         zcfw var2 = zasr.a(this.c, var1, true);
         HashMap var3 = zajh.b(var2);
         var2.c();
         Iterator var4 = var3.values().iterator();

         while(var4.hasNext()) {
            zqe var5 = (zqe)var4.next();
            switch(e.a(var5.d)) {
            case 0:
            case 1:
               this.a.b.n = var5.e;
               break;
            case 2:
            case 3:
               com.aspose.cells.b.a.a.ze.a(this.a.b.j, (Object)var5);
               break;
            case 4:
               this.b.g = var5.e;
            }
         }

      }
   }

   private void c() throws Exception {
      String var1 = this.b.g;
      int var2 = var1.lastIndexOf(47);
      if (var2 != -1) {
         var1 = var1.substring(var2 + 1);
      }

      String var3 = "xl/_rels/" + var1 + ".rels";
      zcfw var4 = zasr.a(this.c, var3, true);
      HashMap var5 = zajh.b(var4);
      this.b.a(var5);
      var4.c();
      zqe var6 = zajh.a(var5, "http://schemas.microsoft.com/office/2006/relationships/vbaProject");
      if (var6 != null) {
         String var7 = "xl/" + com.aspose.cells.b.a.d.zk.b(var6.e);
         if (this.c.a(var7, true) != -1) {
            this.a.getWorksheets().l = new VbaProject(this.a, (zane)null, var7);
         }
      }

   }

   void a(ArrayList var1) {
      Iterator var2 = this.b.b().values().iterator();

      while(var2.hasNext()) {
         zqe var3 = (zqe)var2.next();
         switch(e.a(var3.d)) {
         case 5:
         case 6:
         case 7:
         case 8:
         case 9:
            com.aspose.cells.b.a.a.ze.a(var1, (Object)var3);
            break;
         case 10:
            com.aspose.cells.b.a.a.ze.a(var1, (Object)var3);
            break;
         case 11:
            if (!var3.j) {
               com.aspose.cells.b.a.a.ze.a(var1, (Object)var3);
            }
         }
      }

   }

   private void d() throws Exception {
      zbxz var1 = null;
      String var2 = this.b.m;
      String var3 = this.b.n;
      if (var2 != null) {
         zazw var4 = this.a.getWorksheets().af();
         if (this.c.a(var2, false) != -1) {
            var1 = a(this.c, var2);
            zcdc var5 = new zcdc(var4);
            var5.a(var1);
         }

         if (this.c.a(var3, false) != -1) {
            var1 = a(this.c, var3);
            zcde var11 = new zcde(var4);
            var11.a(var1);
         }

         HashMap var12 = null;
         String var6 = "xl/revisions/_rels/" + com.aspose.cells.b.a.d.zk.b(var2) + ".rels";
         if (this.c.a(var6, false) != -1) {
            zcfw var7 = zasr.a(this.c, var6, true);
            var12 = zajh.b(var7);
            var7.c();
         }

         zcdd var13 = new zcdd(this.b);

         for(int var8 = 0; var8 < var4.getCount(); ++var8) {
            zazv var9 = var4.a(var8);
            if (var9.b.i != null && !"".equals(var9.b.i)) {
               zqe var10 = (zqe)var12.get(var9.b.i);
               var1 = a(this.c, "xl/revisions/" + var10.e);
               var13.a(var1, var9);
            }
         }

      }
   }

   private void e() {
      for(int var1 = 0; var1 < this.a.getWorksheets().getCount(); ++var1) {
         Worksheet var2 = this.a.getWorksheets().get(var1);
         if (var2.b != null && var2.b.getCount() > 0) {
            for(int var3 = 0; var3 < var2.b.getCount(); ++var3) {
               PivotTable var4 = var2.b.get(var3);
               var4.d = this.b.a.getWorksheets().U().b(var4.aa);
               ++var4.d.o;
               if (var4.d != null && var4.d.p != null) {
                  for(int var5 = 0; var5 < var4.d.p.size(); ++var5) {
                     var4.getBaseFields().get(var5).h = (zbqs)var4.d.p.get(var5);
                  }

                  this.a(var4);
               }
            }
         }
      }

   }

   private void a(PivotTable var1) {
      for(int var2 = 0; var2 < var1.getBaseFields().getCount(); ++var2) {
         PivotField var3 = var1.getBaseFields().get(var2);
         if (var3.l() && var1.d.v != null) {
            zaur var4 = var1.d.v;

            for(int var5 = 0; var5 < var4.getCount(); ++var5) {
               zaus var6 = var4.a(var5);
               zbqw var7 = (zbqw)var6.f.e.get(0);
               if ((var7.b() & '\uffff') == var3.t) {
                  if (var3.m == 2) {
                     var7.a = 2;
                  } else if (var3.m == 4) {
                     var7.a = 4;
                  } else if (var3.m == 8) {
                     var7.a = 8;
                  }

                  var6.a(var6.a(), var6.c());
               }
            }
         }
      }

   }

   private void f() throws Exception {
      HashMap var1 = this.b.a();
      ArrayList var2 = this.b.h;

      for(int var3 = 0; var3 < var2.size(); ++var3) {
         zqc var4 = (zqc)var2.get(var3);
         if (!var1.containsKey(var4.e)) {
            throw new CellsException(6, "pivotCache rid " + var4.e + " not found in workbook rels file");
         }

         zqe var5 = (zqe)var1.get(var4.e);
         var5.j = true;
         String var6 = com.aspose.cells.b.a.d.zk.b(var5.e);
         zccr var7 = new zccr(this, this.b, var5.e, var4.c, this.c, var6);
         HashMap var8 = this.a(var6);
         String var9 = "xl/pivotCache/" + var6;
         var7.a(a(this.c, var9));
         var7.a().C = var8;
         var7.b();
      }

   }

   private HashMap a(String var1) throws Exception {
      String var2 = "xl/pivotCache/_rels/" + var1 + ".rels";
      if (this.c.a(var2, true) != -1) {
         zcfw var3 = zasr.a(this.c, var2, true);
         HashMap var4 = zajh.b(var3);
         this.b.b(var4);
         var3.c();
      } else {
         this.b.b((HashMap)null);
      }

      return this.b.c();
   }

   private void b(com.aspose.cells.a.f.zi var1) throws Exception {
      zqe var2 = zajh.a(this.b.a(), "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme");
      if (var2 == null) {
         this.a.b.d = false;
      } else {
         String var3 = "xl/theme/" + com.aspose.cells.b.a.d.zk.b(var2.e);
         this.a.b.f = var3;
         if (var1.a(var3, true) != -1) {
            this.a.b.d = true;
            com.aspose.cells.a.f.zh var4 = var1.a(var3);
            com.aspose.cells.b.a.d.zm var5 = var1.a(var4);
            zcfk var6 = zass.a((com.aspose.cells.b.a.d.zm)var5, (zcft)null, true);
            var5.a();
            zajr var7 = new zajr(this.b, var3);
            var7.a(var6, true);
         }

      }
   }

   private void c(com.aspose.cells.a.f.zi var1) throws Exception {
      Iterator var2 = var1.iterator();

      while(true) {
         String var4;
         String var5;
         do {
            do {
               do {
                  com.aspose.cells.a.f.zh var3;
                  do {
                     if (!var2.hasNext()) {
                        return;
                     }

                     var3 = (com.aspose.cells.a.f.zh)var2.next();
                  } while(var3.c());

                  var4 = var3.b();
                  var5 = zase.aj(var4);
               } while(var4.endsWith(".rels"));
            } while(var4.endsWith(".vml"));
         } while(!var5.equals("drawings") && !var5.equals("charts") && !var5.equals("media"));

         zpk var6 = new zpk();
         var6.b = var4;
         var6.a = var5;
         String var7 = zase.ak(var4);
         if (var1.a(var7, true) != -1) {
            zcfw var8 = zasr.a(var1, var7, true);
            var6.d = zajh.a(var8);
            var8.c();
         }

         com.aspose.cells.b.a.a.ze.a(this.a.b.k, (Object)var6);
      }
   }

   private void d(com.aspose.cells.a.f.zi var1) throws Exception {
      String var2 = "[Content_Types].xml";
      zait var3 = new zait(this.b);
      zcfw var4 = zasr.a(var1, var2, true);
      var3.a(var4);
      var4.c();
   }

   void a(com.aspose.cells.a.f.zi var1) throws Exception {
      Iterator var2 = this.b.c.iterator();

      while(true) {
         while(var2.hasNext()) {
            zpa var3 = (zpa)var2.next();
            var3.m = this.b;
            zqe var4 = (zqe)this.b.b().get(var3.c);
            String var5 = com.aspose.cells.b.a.d.zk.b(var4.e);
            if (var4.e.startsWith("worksheets/")) {
               this.b(var3, var5, var1);
               String var6 = "xl/worksheets/_rels/" + var5 + ".rels";
               if (var1.a(var6, false) != -1) {
                  zcfw var7 = zasr.a(var1, var6, true);
                  var3.e = zajh.b(var7);
                  var7.c();
               }
            } else if (var4.e.startsWith("chartsheets/") && zase.b) {
               this.a(var3, var5, var1);
            } else {
               this.b.a.getWorksheets().removeAt(var3.d.getName());
            }
         }

         return;
      }
   }

   private void a(zpa var1, String var2, com.aspose.cells.a.f.zi var3) throws Exception {
      this.a(var1, 2, var2, var3);
      String var4 = "xl/chartsheets/" + var2;
      zcay var5 = new zcay(this);
      var5.a(var1, a(var3, var4));
      this.e(var1, var3);
      this.g(var1, var3);
      if (var1.i != null) {
         this.a(var1, var3);
      }

   }

   private void b(zpa var1, String var2, com.aspose.cells.a.f.zi var3) throws Exception {
      this.a(var1, 1, var2, var3);
      this.c(var1, var3);
      this.d(var1, var3);
      this.b(var1, var3);
      String var4 = var1.a();
      if (var4 != null) {
         zcbf var5 = new zcbf(this);
         var5.a(var1, a(var3, var4));
      }

      String var7 = "xl/worksheets/" + var2;
      zcej var6 = new zcej(this);
      var6.a(var1, a(var3, var7));
      this.e(var1, var3);
      this.g(var1, var3);
      this.f(var1, var3);
      if (var1.i != null) {
         this.a(var1, var3);
      }

      this.a(var1);
      zavb.a(var1.d, true);
   }

   private void a(zpa var1) throws Exception {
      if (var1.j != null) {
         String var2 = var1.a(var1.j);
         if (var2 != null) {
            String var3 = zase.aD(var2);
            com.aspose.cells.a.f.zh var4 = this.c.a(var3);
            com.aspose.cells.b.a.d.zm var5 = this.c.a(var4);
            byte[] var6 = com.aspose.cells.a.c.zw.a(var5, false);
            var5.a();
            var1.d.getPageSetup().a(var6);
         }
      }

      if (var1.d.n != null && var1.d.n.getCount() > 0) {
         for(int var9 = 0; var9 < var1.d.n.getCount(); ++var9) {
            znb var10 = var1.d.n.a(var9);
            if (var10.b != null) {
               String var11 = var1.a(var10.b);
               if (var11 != null) {
                  String var12 = zase.aD(var11);
                  com.aspose.cells.a.f.zh var13 = this.c.a(var12);
                  com.aspose.cells.b.a.d.zm var7 = this.c.a(var13);
                  byte[] var8 = com.aspose.cells.a.c.zw.a(var7, false);
                  var7.a();
                  var10.e().a(var8);
                  var10.b = null;
               }
            }
         }
      }

   }

   private void a(zpa var1, com.aspose.cells.a.f.zi var2) throws Exception {
      String var3 = zase.aD(var1.a(var1.i));
      com.aspose.cells.a.f.zh var4 = var2.a(var3);
      com.aspose.cells.b.a.d.zm var5 = var2.a(var4);
      byte[] var6 = new byte[(int)var4.a()];
      var5.a(var6, 0, (int)var4.a());
      var5.a();
      var1.d.setBackground(var6);
      com.aspose.cells.b.a.a.ze.a(this.a.b.h, (Object)com.aspose.cells.b.a.d.zk.b(var3));
   }

   private void b(zpa var1, com.aspose.cells.a.f.zi var2) throws Exception {
      ArrayList var3 = zajh.c(var1.e, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable");

      for(int var4 = 0; var4 < var3.size(); ++var4) {
         zqe var5 = (zqe)var3.get(var4);
         String var6 = "xl/pivotTables/" + com.aspose.cells.b.a.d.zk.b(var5.e);
         zccv var7 = new zccv(this);
         zbxz var8 = a(var2, var6);
         if (var8 != null) {
            var7.a(var1, var8);
         }
      }

   }

   private void c(zpa var1, com.aspose.cells.a.f.zi var2) throws Exception {
      ArrayList var3 = zajh.c(var1.e, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/queryTable");

      for(int var4 = 0; var4 < var3.size(); ++var4) {
         zqe var5 = (zqe)var3.get(var4);
         String var6 = "xl/queryTables/" + com.aspose.cells.b.a.d.zk.b(var5.e);
         zccz var7 = new zccz(this);
         zbxz var8 = a(var2, var6);
         if (var8 != null) {
            var7.a(var1, var8);
         }
      }

   }

   private void d(zpa var1, com.aspose.cells.a.f.zi var2) throws Exception {
      ArrayList var3 = zajh.c(var1.e, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table");

      for(int var4 = 0; var4 < var3.size(); ++var4) {
         zqe var5 = (zqe)var3.get(var4);
         String var6 = "xl/tables/" + com.aspose.cells.b.a.d.zk.b(var5.e);
         zcdy var7 = new zcdy(this);
         var7.a(var1, a(var2, var6));
         zcfw var8 = null;
         HashMap var9 = null;
         String var10 = "xl/tables/_rels/" + com.aspose.cells.b.a.d.zk.b(var5.e) + ".rels";
         if (var2.a(var10, false) != -1) {
            var8 = zasr.a(var2, var10, true);
            var9 = zajh.b(var8);
            var8.c();
         }
      }

   }

   private void e(zpa var1, com.aspose.cells.a.f.zi var2) throws Exception {
      String var3 = var1.a(var1.f);
      if (var3 != null) {
         zcfw var4 = null;
         String var5 = "xl/drawings/_rels/" + com.aspose.cells.b.a.d.zk.b(var3) + ".rels";
         var3 = zase.aD(var3);
         HashMap var6 = null;
         if (var2.a(var5, true) != -1) {
            var4 = zasr.a(var2, var5, true);
            var6 = zajh.b(var4);
            var4.c();
         }

         zajs var7 = new zajs(var1, var6, var2, var3);
         var7.a();
         var1.d.g.q = var7.b();
         this.a.b.a(var3);
      }
   }

   private void f(zpa var1, com.aspose.cells.a.f.zi var2) throws Exception {
      String var3 = var1.a(var1.g);
      if (var3 != null) {
         var3 = zase.aD(var3);
         zcfw var4 = zasr.a(var2, var3, true);
         zajc var5 = new zajc();
         ArrayList var6 = var5.a(var4);
         var4.c();
         String var7 = "xl/drawings/_rels/" + com.aspose.cells.b.a.d.zk.b(var3) + ".rels";
         if (var6 == null) {
            return;
         }

         if (var2.a(var7, true) == -1) {
            return;
         }

         var4 = zasr.a(var2, var7, true);
         HashMap var8 = zajh.b(var4);
         var4.c();
         if (var8 == null || var8.size() == 0) {
            throw new CellsException(6, var7 + " does not exist or is empty");
         }

         for(int var9 = 0; var9 < var6.size(); ++var9) {
            zou var10 = (zou)var6.get(var9);
            if (var10.a != null) {
               if (!var8.containsKey(var10.a)) {
                  throw new CellsException(6, var7 + " does not contains relId " + var10.a);
               }

               zqe var11 = (zqe)var8.get(var10.a);
               String var12 = zase.aD(var11.e);
               com.aspose.cells.a.f.zh var13 = var2.a(var12);
               com.aspose.cells.b.a.d.zm var14 = var2.a(var13);
               byte[] var15 = new byte[(int)var13.a()];
               var14.a(var15, 0, (int)var13.a());
               var14.a();
               Picture var16 = var1.d.getPageSetup().a(var10.a(), var15);
               var10.a(var16, this.a.getWorksheets().L());
            }
         }
      }

   }

   private void g(zpa var1, com.aspose.cells.a.f.zi var2) throws Exception {
      String var3 = var1.a(var1.h);
      if (var3 != null) {
         zcfw var4 = null;
         String var5 = "xl/drawings/_rels/" + com.aspose.cells.b.a.d.zk.b(var3) + ".rels";
         var3 = zase.aD(var3);
         HashMap var6 = null;
         if (var2.a(var5, false) != -1) {
            var4 = zasr.a(var2, var5, true);
            var6 = zajh.a(var4, this.b, this.b.a, var2);
            var4.c();
         }

         zaiz var7 = new zaiz(var1, var6, var2, var3);
         var7.a();
         if (var7.b().size() > 0) {
            var1.d.t().a(var7.b());
         }

         this.a.b.a(var3);
      }
   }

   private void a(zpa var1, int var2, String var3, com.aspose.cells.a.f.zi var4) throws Exception {
      String var5 = null;
      if (var2 == 1) {
         var5 = "xl/worksheets/_rels/" + var3 + ".rels";
      } else {
         if (var2 != 2) {
            throw new CellsException(16, "Cells Internal error, unsupported sheet type");
         }

         var5 = "xl/chartsheets/_rels/" + var3 + ".rels";
      }

      if (var4.a(var5, false) != -1) {
         zcfw var6 = zasr.a(var4, var5, true);
         var1.e = zajh.b(var6);
         var6.c();
         var1.b(var1.d.g.j);
      }

   }

   void b(zbxz var1) throws Exception {
      int var2 = var1.a();
      if (var2 == 159) {
         zbpx var3 = this.a.getWorksheets().g;
         byte[] var4 = this.a(var1);
         int var5 = com.aspose.cells.b.a.zc.a(var4, 0);
         boolean var6 = false;
         boolean var7 = false;
         String var8 = null;
         boolean var9 = false;

         for(int var10 = 0; var10 < var5; ++var10) {
            var2 = var1.a();
            if (var2 != 19) {
               break;
            }

            var4 = this.a(var1);
            var6 = (var4[0] & 255 & 1) != 0;
            var7 = (var4[0] & 255 & 2) != 0;
            byte var11 = 1;
            int[] var12 = new int[]{var11};
            var8 = zcch.a(var4, var12);
            int var18 = var12[0];
            if (var6) {
               int var17 = com.aspose.cells.b.a.zc.a(var4, var18);
               byte[] var13 = new byte[var17 * 4];
               var18 += 4;

               for(int var14 = 0; var14 < var17; ++var14) {
                  System.arraycopy(var4, var18, var13, var14 * 4, 4);
                  int var15 = com.aspose.cells.b.a.zc.e(var4, var18 + 2) & '\uffff';
                  if (var15 < this.b.d().size()) {
                     int var16 = (Integer)this.b.d().get(var15);
                     System.arraycopy(com.aspose.cells.b.a.zc.a(var16), 0, var13, var14 * 4 + 2, 2);
                  }

                  var18 += 4;
               }

               var3.a(var8, var10, var13, (Object)null);
            } else {
               zayy var19 = new zayy(var8, 0);
               var3.a(var19, var10);
            }
         }

      }
   }
}
